package com.suitsoft.ut.web;

import java.io.PrintWriter;
import java.util.List;

import net.sf.json.JSONArray;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.opensymphony.xwork2.ActionSupport;
import com.suitsoft.ut.entity.base.College;
import com.suitsoft.ut.service.base.CollegeManager;

/**
 * 学院的自动补全
 *@author Suineg
 */
public class AutoComplateCollegeAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6620002742576123047L;
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private CollegeManager collegeManager;
	private String collegeName;

	@Override
	public String execute() throws Exception {
		PrintWriter out = Struts2Utils.getResponse().getWriter();
		Page<College> page = new Page<College>(100);
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		page = collegeManager.findLikeByName(filters, page);
		JSONArray array = new JSONArray();
		if(page.getTotalCount() != 0){
			for(College c : page.getResult()){
				array.add(c.getCollegeName());
			}
		}
		out.print(array.toString());
		out.flush();
		out.close();
		return null;
	}

	public String getCollegeName() {
		return collegeName;
	}
	public void setCollegeName(String collegeName) {
		this.collegeName = collegeName;
	}
}

